package com.example.administrator.express.activity;

import android.app.Activity;
import android.os.Bundle;

import com.example.administrator.express.R;
import com.example.administrator.express.http.HttpClient;
import com.example.administrator.express.http.HttpResponseHandler;
import com.example.administrator.express.utils.SharedPreferences;

import java.io.IOException;

import okhttp3.FormBody;
import okhttp3.Request;

/**
 * Created by Administrator on 2016/9/20.
 */
public class activity_test extends Activity{
    int count;
    private Integer countformonth[]=new Integer[12];
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.appstart);
        initdata();

    }
    public void  initdata(){
        String action ="getcountformonth";
//        SharedPreferences sharedPreferences=SharedPreferences.getInstance();
//        Integer loginId =sharedPreferences.getInt("loginId",0);
        int a= getcount("1",action,100,"2016-09");
        for (int i=0;i<=11;i++){
            countformonth[i]=a;
        }

    }
    public Integer getcount(final String posttype,String action,int loginId,String date){

        try{
            String url="http://oa24406206.carp.mopaasapp.com/";
            url=url+action;
            FormBody formBody=new FormBody.Builder()
                    .add("posttype",posttype)
                    .add("loginId",String.valueOf(loginId))
                    .add("date",date)
                    .build();

            HttpClient.post(url,formBody,new HttpResponseHandler(){
                @Override
                public void onSuccess(int statusCode, String content) {
                    System.out.println("成功:"+content);
                    count=Integer.valueOf(content);
                }

                @Override
                public void onFailure(Request request, IOException e) {
                    super.onFailure(request, e);
                    System.out.println("获取失败:");
                }
            });
        }catch(Exception e){
            e.printStackTrace();
        }
        return count;
    }
}
